﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AchtungDieKurve
{
    public partial class Speelveld : Form
    {
        Mainform mainform = new Mainform();
        Worm worm1 = null;
        Worm worm2 = null;
        Worm worm3 = null;
        Worm worm4 = null;
        Graphics graphics = null;
        Pen pen1 = null;
        Pen pen2 = null;
        Pen pen3 = null;
        Pen pen4 = null;
        bool isbegonnen = false;
        List<Worm> meedoenWormen = new List<Worm>();

        public Speelveld(Mainform mainform)
        {
            InitializeComponent();
            this.mainform = mainform;
            maakWormen();
        }

        private void maakWormen()
        {
            Random random1 = new Random();

            if (mainform.cbSp1.Checked)
            {
                pen1 = new Pen(Color.Blue, 3);
                worm1 = new Worm(random1.Next(360), 10, 5, random1.Next(40, this.ClientSize.Width - 40), random1.Next(40, this.ClientSize.Height - 40), Keys.Left, Keys.Right, Keys.Down, Color.Blue, pen1);

                meedoenWormen.Add(worm1);
            }
            if (mainform.cbSp2.Checked)
            {
                pen2 = new Pen(Color.Red, 3);
                worm2 = new Worm(random1.Next(360), 10, 5, random1.Next(40, this.ClientSize.Width - 40), random1.Next(40, this.ClientSize.Height - 40), Keys.NumPad3, Keys.NumPad9, Keys.NumPad6, Color.Red, pen2);

                meedoenWormen.Add(worm2);
            }
            if (mainform.cbSp3.Checked)
            {
                pen3 = new Pen(Color.Green, 3);
                worm3 = new Worm(random1.Next(360), 10, 5, random1.Next(40, this.ClientSize.Width - 40), random1.Next(40, this.ClientSize.Height - 40), Keys.Q, Keys.Z, Keys.A, Color.Green, pen3);

                meedoenWormen.Add(worm3);
            }
            if (mainform.cbSp4.Checked)
            {
                pen4 = new Pen(Color.Yellow, 3);
                worm4 = new Worm(random1.Next(360), 10, 5, random1.Next(40, this.ClientSize.Width - 40), random1.Next(40, this.ClientSize.Height - 40), Keys.C, Keys.B, Keys.V, Color.Yellow, pen4);

                meedoenWormen.Add(worm4);
            }
        }

        private void Speelveld_Paint(object sender, PaintEventArgs e)
        {
            graphics = e.Graphics;
            if (!isbegonnen)
            {
                foreach (Worm worm in meedoenWormen)
                {
                    graphics.DrawLine(worm.Pen, worm.Xpos, worm.Ypos, worm.Xpos + 20, worm.Ypos);

                }
            }
            else
            {
                
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Refresh();
        }

        private void timerBeginCD_Tick(object sender, EventArgs e)
        {
            timerBeginCD.Enabled = false;
            isbegonnen = true;
        }
    }
}
